from django.db import models
import os


def firmware_upload_path(instance, filename):
    return f"firmware/{instance.version}/{filename}"


class Firmware(models.Model):
    version = models.CharField(max_length=32, unique=True)  # 版本号
    file = models.FileField(upload_to=firmware_upload_path)  # 固件文件
    release_notes = models.TextField()                      # 发布说明
    is_active = models.BooleanField(default=True)           # 是否可升级
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.version} ({'Active' if self.is_active else 'Inactive'})"